﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		Plugin.Builder.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion
 

using System;
using Topics.Radical.Validation;

namespace Dexter.Domain.Model {
	public partial class Plugin {
		/// <summary>
		/// Creates a new instance of <see cref="Plugin"/>.
		/// </summary>
		/// <param name="identifier">The identifier.</param>
		/// <param name="name">The name of the Blog Roll.</param>
		/// <param name="version">The link.</param>
		/// <param name="registrationName">Name of the registration.</param>
		/// <returns>
		/// A new instance of <see cref="BlogRoll"/>
		/// </returns>
		/// <exception cref="ArgumentNullException"> If <paramref name="identifier"/> is equal to <c>Guid.Empty</c>.</exception>
		/// <exception cref="ArgumentNullException"> If <paramref name="name"/> is <c>null</c>.</exception>
		/// <exception cref="ArgumentOutOfRangeException"> If <paramref name="name"/> is <c>empty</c>.</exception>
		/// <exception cref="ArgumentNullException"> If <paramref name="version"/> is <c>null</c>.</exception>
		/// <exception cref="ArgumentNullException"> If <paramref name="registrationName"/> is <c>null</c>.</exception>
		/// <exception cref="ArgumentException"> If <paramref name="registrationName"/> is <c>empty</c>.</exception>
		public static Plugin CreateNewPlugin(Guid identifier, string name, System.Version version, string registrationName)
		{
			Ensure.That ( version )
				.Named ( "version" )
				.WithPreview ( ( v, e ) => Logger.Warn ( v.GetFullErrorMessage ( ), e ) )
				.IsNotNull ( )
				.WithMessage ( "Invalid plugin version." );

			if(identifier == Guid.Empty)
				throw new ArgumentException("Invalid plugin identifier.", "identifier");

			Ensure.That ( name )
				.Named ( "name" )
				.WithPreview ( ( v, e ) => Logger.Warn ( v.GetFullErrorMessage ( ), e ) )
				.IsNotNullNorEmpty ( )
				.WithMessage ( "Invalid plugin name." );

			if (registrationName == null)
				throw new ArgumentNullException("registrationName");

			if (registrationName == "")
				throw new ArgumentNullException("registrationName");

			return new Plugin(identifier, name, version, registrationName);
		}
	}
}
	